package com.hzc.springchan.controller;

import com.hzc.springchan.annotation.CApi;
import com.hzc.springchan.annotation.CParam;
import com.hzc.springchan.annotation.CParams;
import com.hzc.springchan.bean.request.Request;
import com.hzc.springchan.bean.response.Response;
import com.hzc.springchan.constant.System;
import com.hzc.springchan.enums.CParamCheck;
import com.hzc.springchan.enums.CResource;
import com.hzc.springchan.service.IRouteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 用户管理模块
 * @Author: chen990627
 * @Date: 2022/11/01
 **/
@CrossOrigin
@RestController
@RequestMapping("/user")
public class UserController extends BaseController {

    @Autowired
    private IRouteService routeService;

    /**
     * 用户登录
     *
     * @param request
     * @return
     */
    @PostMapping("/login")
    @CParams({
            @CParam(params = {"userName", "passWord"}, values = CParamCheck.NULL_CHECK)
    })
    @CApi(skipTokenCheck = true, resource = CResource.USER_LOGIN)
    public Response userLogin(@RequestBody Request request) {
        return requestRoute(routeService);
    }

    /**
     * 用户注册
     *
     * @param request
     * @return
     */
    @PostMapping("/register")
    @CParams({
            @CParam(params = {"userName", "passWord", "nickName", "verifyCode"}, values = CParamCheck.NULL_CHECK)
    })
    @CApi(skipTokenCheck = true, resource = CResource.USER_REGISTER)
    public Response userRegister(@RequestBody Request request) {
        return requestRoute(routeService);
    }

    /**
     * 查看用户信息
     *
     * @param token
     * @return
     */
    @GetMapping("/info")
    @CParams({
            @CParam(params = {System.RequestParam.TOKEN}, values = CParamCheck.NULL_CHECK)
    })
    @CApi(skipTokenCheck = false, resource = CResource.GET_USER_INFO)
    public Response getUserInfo(@RequestParam String token) {
        return requestRoute(routeService);
    }

    /**
     * 修改用户信息
     *
     * @param request
     * @return
     */
    @PutMapping("/put_info")
    @CParams({
            @CParam(params = {"nickName", "passWord", System.RequestParam.TOKEN}, values = CParamCheck.NULL_CHECK)
    })
    @CApi(skipTokenCheck = false, resource = CResource.PUT_USER_INFO)
    public Response putUserInfo(@RequestBody Request request) {
        return requestRoute(routeService);
    }
}
